<template>
  <el-dialog v-model="dialogVisible" title="查看企业" width="700" @close="emit('submit')">
    <el-table style="height: 400px" :data="tableData">
      <el-table-column prop="name" label="企业名称"></el-table-column>
      <el-table-column prop="registrationNo" label="企业编号"></el-table-column>
      <el-table-column prop="registeredAddress" label="注册地址"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>

<script setup>
import { ref } from 'vue'
import { deleteEnterpriseToIndustry } from '@/api/enterprise'
import { ElMessage } from 'element-plus'

const dialogVisible = ref(false)
const industryId = ref(0)
const tableData = ref([])
const emit = defineEmits(['submit'])
const openDialog = (data) => {
  console.log(data)
  industryId.value = data.id
  tableData.value = data.enterprises
  dialogVisible.value = true
}
const handleDelete = async (row) => {
  const res = await deleteEnterpriseToIndustry({
    industryId: industryId.value,
    enterpriseId: row.id,
  })
  if (res.status === 200 || res.status === 201) {
    ElMessage.success('删除成功')
    tableData.value = tableData.value.filter((item) => item.id !== row.id)
  } else {
    ElMessage.error(res.data.data || '系统繁忙，请稍后再试')
  }
}
// 关闭弹窗方法
const closeDialog = () => {
  dialogVisible.value = false
}
defineExpose({ openDialog, closeDialog })
</script>

<style>
</style>
